package application.client.gui.components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import middleware.datacontainer.groupPropertiesChange.GroupPropertiesContainer;

public class GroupSettingPanel extends JPanel {

	
	private GroupPropertiesContainer actualGroupContainer;
	
	private JLabel descriptionLabel;
	private JTextField descriptionTextField;
	private JLabel loanDureLabel;
	private JTextField loanDureTextField;
	private JTextField annualFeeTextField;
	private JLabel annualFeeLabel;
	private JTextField lendingExtensionTextField;
	private JLabel lendingExtensionLabel;
	private JLabel noExtensionLabel;
	private JTextField noExtensionField;
	private JLabel groupIdLabel;
	private JTextField groupIdTextField;
	
	public GroupSettingPanel()
	{
		super(true);
		setLayout(null);
		setBorder(BorderFactory.createTitledBorder("Settings"));
		setBackground(Color.white);
		setPreferredSize(new Dimension(250,313));
		init();
	}
	
	private void init()
	{
		{
			groupIdLabel = new JLabel();
			add(groupIdLabel);
			groupIdLabel.setText("ID");
			groupIdLabel.setBounds(40, 30, 100, 20);
			groupIdLabel.setSize(100, 20);
		}
		{
			groupIdTextField = new JTextField();
			add(groupIdTextField);
			groupIdTextField.setBounds(140, 30, 100, 20);
			groupIdTextField.setEditable(false);
			groupIdTextField.setBackground(Color.white);
		}
		{
			descriptionLabel = new JLabel();
			add(descriptionLabel);
			descriptionLabel.setText("Description");
			descriptionLabel.setBounds(40, 60, 100, 20);
			descriptionLabel.setSize(100, 20);
		}
		{
			descriptionTextField = new JTextField();
			add(descriptionTextField);
			descriptionTextField.setBounds(140, 60, 100, 20);

			descriptionTextField.setEditable(true);
			descriptionTextField.setBackground(Color.white);
		}
		{
			loanDureLabel = new JLabel();
			add(loanDureLabel);
			loanDureLabel.setText("LoanDurationInDays");
			loanDureLabel.setBounds(40, 90, 100, 20);
			loanDureLabel.setSize(100, 20);
		}
		{
			loanDureTextField = new JTextField();
			add(loanDureTextField);
			loanDureTextField.setBounds(140, 90, 100, 20);

			loanDureTextField.setEditable(true);
			loanDureTextField.setBackground(Color.white);
		}
		{
			annualFeeLabel = new JLabel();
			add(annualFeeLabel);
			annualFeeLabel.setText("AnnualFee");
			annualFeeLabel.setBounds(40, 120, 100, 20);
			annualFeeLabel.setSize(100, 20);
		}
		{
			annualFeeTextField = new JTextField();
			add(annualFeeTextField);
			annualFeeTextField.setBounds(140, 120, 100, 20);

			annualFeeTextField.setEditable(true);
			annualFeeTextField.setBackground(Color.white);
		}
		{
			lendingExtensionLabel = new JLabel();
			add(lendingExtensionLabel);
			lendingExtensionLabel.setText("LendingExtension");
			lendingExtensionLabel.setBounds(40, 150, 100, 20);
			lendingExtensionLabel.setSize(100, 20);
		}
		{
			lendingExtensionTextField = new JTextField();
			add(lendingExtensionTextField);
			lendingExtensionTextField.setBounds(140, 150, 100, 20);

			lendingExtensionTextField.setEditable(true);
			lendingExtensionTextField.setBackground(Color.white);
		}
		{
			noExtensionLabel = new JLabel();
			add(noExtensionLabel);
			noExtensionLabel.setText("AllowedNoOfExtension");
			noExtensionLabel.setBounds(40, 180, 100, 20);
			noExtensionLabel.setSize(100, 20);
		}
		{
			noExtensionField = new JTextField();
			add(noExtensionField);
			noExtensionField.setBounds(140, 180, 100, 20);

			noExtensionField.setEditable(true);
			noExtensionField.setBackground(Color.white);
		}
	}
	
	public void setGroupAttributes(GroupPropertiesContainer g)
	{
		actualGroupContainer=g;
		groupIdTextField.setText("" + g.getId());
		descriptionTextField.setText(g.getDescription());
		loanDureTextField.setText(""+g.getLoanDuration());
		annualFeeTextField.setText(""+g.getAnnualFee());
		lendingExtensionTextField.setText(""+g.getLendingExtension());
		noExtensionField.setText(""+g.getAllowedNoOfExtension());
		
	}
	public GroupPropertiesContainer getAttributes()
	{
		actualGroupContainer.setDescription(descriptionTextField.getText());
		actualGroupContainer.setLoanDuration(Integer.parseInt(loanDureTextField.getText()));
		actualGroupContainer.setAnnualFee(Float.parseFloat(annualFeeTextField.getText()));
		actualGroupContainer.setLendingExtension(Integer.parseInt(lendingExtensionTextField.getText()));
		actualGroupContainer.setAllowedNoOfExtension(Integer.parseInt(noExtensionField.getText()));
		return actualGroupContainer;
	}
}
